package com.yhj.reggie.mapper;

import com.yhj.reggie.entity.Category;
import com.yhj.reggie.entity.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CategoryMapper {

    //添加分类和套餐
    @Insert("insert into category values (null,#{type},#{name},#{sort}," +
            "#{createTime},#{updateTime},#{createUser},#{createUser})")
    Integer save(Category category);

    //根据分类名找分类
    @Select("select * from category where name=#{name}")
    Category findByName(String name);

    //分页查询
    @Select("select * from category order by sort")
    List<Category> findByPage();

    //删除
    @Delete("delete from category where id=#{id}")
    Integer delete(Long id);
    //修改
//    @Update("update category set type=#{type},name=#{name},sort=#{sort},update_time=#{updateTime},update_user=#{updateUser}")
    Integer update(Category category);

    //根据分类名找分类
    @Select("select * from category where name=#{name} and id != #{id}")
    Category findByNameE(Category category);

    //分页查根据分类
    List<Category> findAllByType(Integer type);

    //根据id查菜分类
    @Select("select * from category where id = #{id}")
    Category findById(Long id);
}
